// pages/jianzhix/jianzhix.js
const db = wx.cloud.database().collection('school')
Page({

  data: {
    listData: [],
    jianzhiname: '',
    markers: [{
      id: 0,
      latitude: 23.099994,
      longitude: 113.324520,
      width: 50,
      height: 50
    }],
    controls: [{
      id: 1,
      position: {
        left: 0,
        top: 300 - 50,
        width: 50,
        height: 50
      },
      clickable: true
    }]
  },
  onLoad: function (options) {
    this.setData({
      jianzhiname:options.jianzhiname
    })
    this.getData ()
  },
  getData () { // 获取数据
    let thiss = this
    db.get({
      success (res) {
        var data = res.data
        for(let i=0;i<data.length;i++){
          if(data[i].jianzhiname === thiss.data.jianzhiname){
            thiss.setData({
              listData:data[i]
            })
          }
        }
      }
    })
  },
  regionchange(e) {
    console.log(e.type)
  },
  markertap(e) {
    console.log(e.detail.markerId)
  },
  controltap(e) {
    console.log(e.detail.controlId)
  },
  creatTable () {
    var table = 'chatroom5'
    wx.cloud.callFunction({
      name: 'createCollection',
      data: {
        table
      },
      success (res) {
        wx.setStorageSync("open", res.result.openid);
        console.log(res)
        wx.navigateTo({
          url: `/pages/chat/chat?tablename=${table}`
        })
      },
      fail (err) {
        console.log(err)
      }
    })
  }
})